﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;

namespace EVEApi
{
    public class Datenbank
    {

        SQLiteCommand SqllCom = new SQLiteCommand();
        SQLiteConnection Sqlcon = new SQLiteConnection(@"Data Source = Sqlite.dat");
        public void Verbindung()
        {

            SqllCom.Connection = Sqlcon;
            SqllCom.Connection.Open();


        }

        public void TabellenErstellen()
        {
            SqllCom.Connection = Sqlcon;
            SqllCom.CommandText = "Create TABLE IF NOT EXISTS Trans (transactionID INTEGER NOT NULL, " + Environment.NewLine
             + "quantity INTEGER NOT NULL, typeID INTEGER NOT NULL, price DOUBLE NOT NULL)";
            SqllCom.Connection.Open();
            SqllCom.ExecuteNonQuery();
            SqllCom.Connection.Close();
        }

        public void InDatenbankSpeichern(DataTable DT)
        {
            SqllCom.Connection = Sqlcon;
            SqllCom.CommandText = "Insert Into Trans (transactionID, quantity, typeID, price)" + Environment.NewLine
                                + " Values (@TransactionID, @quantity, @typeID, @price)";
            SqllCom.Parameters.Add("@TransactionID", DbType.Double, 1, "transactionID");
            SqllCom.Parameters.Add("@quantity", DbType.Int32, 1, "quantity");
            SqllCom.Parameters.Add("@typeID", DbType.Int32, 1, "typeID");
            SqllCom.Parameters.Add("@price", DbType.Double, 10000000, "price");

            SQLiteDataAdapter SQLDA = new SQLiteDataAdapter(SqllCom);
            SQLDA.InsertCommand = SqllCom;
            SQLDA.Update(DT);
        
        }
    }
}
